﻿using System;

namespace YKXiangQi.ViewModels
{
    public class StatusBarViewModel: ViewModelBase
    {
        private int _depth;
        private double _time;
        private int _score;
        private int _currentMoveNumber;
        private string _currentMove;
        private double _nps;

        public int Depth
        {
            get { return _depth; }
            set
            {
                _depth = value;
                RaisePropertyChanged(() => Depth);
            }
        }

        public double Time
        {
            get { return _time; }
            set
            {
                _time = value;
                RaisePropertyChanged(() => Time);
            }
        }

        public int Score
        {
            get { return _score; }
            set
            {
                _score = value;
                RaisePropertyChanged(() => Score);
            }
        }

        public int CurrentMoveNumber
        {
            get { return _currentMoveNumber; }
            set
            {
                _currentMoveNumber = value;
                RaisePropertyChanged(() => CurrentMoveNumber);
                RaisePropertyChanged(() => Move);
            }
        }

        public string CurrentMove
        {
            get { return _currentMove; }
            set
            {
                _currentMove = value;
                RaisePropertyChanged(() => CurrentMove);
                RaisePropertyChanged(() => Move);
            }
        }

        public double Nps
        {
            get { return _nps; }
            set
            {
                _nps = value;
                RaisePropertyChanged(() => Nps);
                RaisePropertyChanged(() => NodesPerSecond);
            }
        }

        public string Move
        {
            get
            {
                return string.Format("{0}.{1}", CurrentMoveNumber,
                                     string.IsNullOrEmpty(CurrentMove) ? string.Empty : CurrentMove.ToUpper());
            }
        }

        public string NodesPerSecond
        {
            get { return string.Format("{0}k", Math.Round(Nps/1000)); }
        }

        public void Clear()
        {
            Depth = 0;
            Time = 0;
            Score = 0;
            CurrentMoveNumber = 0;
            Nps = 0;
        }
    }
}
